package org.robot.scm.platform.server.common;

import java.io.PrintWriter;

public class BackPrintWriter extends PrintWriter {

    private OnDataWrittenListener listener;

    private PrintWriter writer;

    public interface OnDataWrittenListener {

        void onDataWritten(String data);
    }

    public BackPrintWriter(PrintWriter writer, OnDataWrittenListener listener) {
        super(writer);
        this.writer = writer;
        this.listener = listener;
    }

    @Override
    public void println(String line) {
        writer.println(line);
        listener.onDataWritten(line);
    }

    @Override
    public void print(String line) {
        writer.print(line);
        listener.onDataWritten(line);
    }

    @Override
    public void println(Object object) {
        println(String.valueOf(object));
    }

    @Override
    public void print(Object object) {
        println(String.valueOf(object));
    }


}
